Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

163
Views
how do I convert \n and \t to "\n" and "\t" in Javascript?

My question is simple, I want this string:

//input string
<div class=“element”>
    <span>text</span>
</div>

to look like this:

//output string
<div class="element">\n\t<span>text</span>\n</div>

First I thought that I can do it with the .replace() function but I don't know how to target the \n and \t in a way that I can replace those.

I use a textbox as in and output. I need it in one line because I want to writ it to a JSON object and it does not support multiline strings.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!